<html>
<head>
<meta NAME="author" CONTENT="Peter Csizmadia">
    <script type="text/javascript" src="../../sh_main.js"></script>
    <script type="text/javascript" src="../../sh_javascript.js"></script>
    <script type="text/javascript" src="../../sh_html.js"></script>
    <link REL ="stylesheet" TYPE="text/css" HREF="../../sh_nedit.css" TITLE="Style">
<link REL ="stylesheet" TYPE="text/css" HREF="../../../marvinmanuals.css" TITLE="Style">
<title>MarvinSketch Example - Import/export of built-in and
	user defined molecule formats in JavaScript</title>
</head>
<body onload="sh_highlightDocument();">

<h1>MarvinSketch Example - Import/export of built-in and
	user defined molecule formats in JavaScript</h1>

<p>Press the <b>Import</b> button to import the molfile into MarvinSketch.
Change the molecule (delete some atoms or bonds, draw new ones),
select a molecule format from the list, then try the <b>Export</b>
buttons.

You can import a SMARTS string from the text box by using the <b>Import
SMARTS</b> button.</p>
<p></p>
<center>
<form NAME=MolForm onSubmit="return false">
<textarea NAME="MolTxt" ROWS=20 COLS=70>
3,7-Dihydro-1,3,7-trimethyl-1H-purine-2,6-dione
  Marvin  07099920012D

 14 15  0  0  0  0  0  0  0  0999 V2000
   -2.0245   -2.6287    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
   -2.0245   -1.0107    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
   -1.7156   -0.0596    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.4367   -1.8197    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -3.8415   -0.8197    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -5.5735   -0.8197    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -4.7075   -2.3196    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -3.8415   -3.8197    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -2.9755   -2.3196    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -2.9755   -1.3197    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -3.8415    0.1803    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
   -5.5735   -2.8197    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
   -4.7075   -1.3197    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
   -3.8415   -2.8197    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
  5 13  1  0  0  0  0
 13  7  1  0  0  0  0
  7 14  1  0  0  0  0
 14  9  1  0  0  0  0
  9 10  2  0  0  0  0
  5 10  1  0  0  0  0
  4  2  1  0  0  0  0
  2 10  1  0  0  0  0
  9  1  1  0  0  0  0
  4  1  2  0  0  0  0
  2  3  1  0  0  0  0
  5 11  2  0  0  0  0
 13  6  1  0  0  0  0
  7 12  2  0  0  0  0
 14  8  1  0  0  0  0
M  END
</textarea>
<p>
<input TYPE=BUTTON VALUE="Import" onClick="importMol(null)">
<input TYPE=BUTTON VALUE="Import SMARTS" onClick="importMol('smarts:')">
</p>
<p>Export format:
<select name="molformat">
<option VALUE="cml">cml</option>
<option VALUE="csmol">csmol</option>
<option VALUE="csrdf">csrdf</option>
<option VALUE="csrxn">csrxn</option>
<option VALUE="cssdf">cssdf</option>
<option SELECTED VALUE="mol">mol</option>
<option VALUE="mrv">mrv</option>
<option VALUE="name">name</option>
<option VALUE="rdf">rdf</option>
<option VALUE="rxn">rxn</option>
<option VALUE="smarts">smarts</option>
<option VALUE="smiles">smiles</option>
<option VALUE="sdf">sdf</option>
<option VALUE="sybyl">sybyl</option>
</select>
<input TYPE=BUTTON VALUE="Export" onClick="exportMol(getFormat())">
<input TYPE=BUTTON VALUE="Undo" onClick="undo()">
<input TYPE=BUTTON VALUE="Redo" onClick="redo()">
<input TYPE=BUTTON VALUE="Clean 2D" onClick="clean2D()">
<input TYPE=BUTTON VALUE="Clean 3D" onClick="clean3D()"></p>
</form>

<script LANGUAGE="JavaScript1.1" SRC="../../../marvin.js"></script>
<script LANGUAGE="JavaScript1.1">
<!--
function getFormat() {
    var sel = document.MolForm.molformat;
    var v = document.MolForm.molformat[sel.selectedIndex].value;
    return v;
}

function undo() {
    if(document.MSketch != null) {
        document.MSketch.undo();
    }
}

function redo() {
    if(document.MSketch != null) {
        document.MSketch.redo();
    }
}

function clean2D() {
    if(document.MSketch != null) {
        document.MSketch.clean2D();
    }
}

function clean3D() {
    if(document.MSketch != null) {
        document.MSketch.clean3D();
    }
}

function importMol(opts) {
	if(document.MSketch != null) {
		var s = document.MolForm.MolTxt.value;
		document.MSketch.setMol(s, opts);
	} else {
		alert("Cannot import molecule:\n"+
		      "no JavaScript to Java communication in your browser.\n");
	}
}
function exportMol(format) {
	if(document.MSketch != null) {
		var s = document.MSketch.getMol(format);
		s = unix2local(s); // Convert "\n" to local line separator
		document.MolForm.MolTxt.value = s;
	} else {
		alert("Cannot import molecule:\n"+
		      "no JavaScript to Java communication in your browser.\n");
	}
}
msketch_name = "MSketch";
msketch_begin("../../..", 540, 480);
msketch_end();
//-->
</script>
</center>
<p>
Several Marvin supported  <a HREF="../../../help/formats/formats.html">file formats</a> demonstrated here.
<blockquote>
<pre class="sh_html">
&lt;form NAME=MolForm onSubmit=&quot;return false&quot;&gt;
&lt;textarea NAME=&quot;MolTxt&quot; ROWS=20 COLS=70&gt;
3,7-Dihydro-1,3,7-trimethyl-1H-purine-2,6-dione
  Marvin  07099920012D

 14 15  0  0  0  0  0  0  0  0999 V2000
   -2.0245   -2.6287    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
   -2.0245   -1.0107    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
   -1.7156   -0.0596    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.4367   -1.8197    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -3.8415   -0.8197    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -5.5735   -0.8197    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -4.7075   -2.3196    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -3.8415   -3.8197    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -2.9755   -2.3196    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -2.9755   -1.3197    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -3.8415    0.1803    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
   -5.5735   -2.8197    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0
   -4.7075   -1.3197    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
   -3.8415   -2.8197    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
  5 13  1  0  0  0  0
 13  7  1  0  0  0  0
  7 14  1  0  0  0  0
 14  9  1  0  0  0  0
  9 10  2  0  0  0  0
  5 10  1  0  0  0  0
  4  2  1  0  0  0  0
  2 10  1  0  0  0  0
  9  1  1  0  0  0  0
  4  1  2  0  0  0  0
  2  3  1  0  0  0  0
  5 11  2  0  0  0  0
 13  6  1  0  0  0  0
  7 12  2  0  0  0  0
 14  8  1  0  0  0  0
M  END
&lt;/textarea&gt;
&lt;p&gt;
&lt;input TYPE=BUTTON VALUE=&quot;Import&quot; onClick=&quot;importMol('null')&quot;&gt;
&lt;input TYPE=BUTTON VALUE=&quot;Import SMARTS&quot; onClick=&quot;importMol('smarts:')&quot;&gt;
&lt;/p&gt;
&lt;p&gt;Export format:
&lt;select NAME="molformat"&gt;
&lt;option VALUE="cml"&gt;cml&lt;/option&gt;
&lt;option VALUE="csmol"&gt;csmol&lt;/option&gt;
&lt;option VALUE="csrdf"&gt;csrdf&lt;/option&gt;
&lt;option VALUE="csrxn"&gt;csrxn&lt;/option&gt;
&lt;option VALUE="cssdf"&gt;cssdf&lt;/option&gt;
&lt;option SELECTED VALUE="mol"&gt;mol&lt;/option&gt;
&lt;option VALUE="mrv"&gt;mrv&lt;/option&gt;
&lt;option VALUE="name"&gt;name&lt;/option&gt;
&lt;option VALUE="rdf"&gt;rdf&lt;/option&gt;
&lt;option VALUE="rxn"&gt;rxn&lt;/option&gt;
&lt;option VALUE="smarts"&gt;smarts&lt;/option&gt;
&lt;option VALUE="smiles"&gt;smiles&lt;/option&gt;
&lt;option VALUE="sdf"&gt;sdf&lt;/option&gt;
&lt;option VALUE="sybyl"&gt;sybyl&lt;/option&gt;
&lt;/select&gt;
&lt;input TYPE=BUTTON VALUE=&quot;Export&quot; onClick=&quot;exportMol(document.MolForm.molformat.value)&quot;&gt;
&lt;input TYPE=BUTTON VALUE=&quot;Undo&quot; onClick=&quot;undo()&quot;&gt;
&lt;input TYPE=BUTTON VALUE=&quot;Redo&quot; onClick=&quot;redo()&quot;&gt;
&lt;input TYPE=BUTTON VALUE=&quot;Clean 2D&quot; onClick=&quot;clean2D()&quot;&gt;
&lt;input TYPE=BUTTON VALUE=&quot;Clean 3D&quot; onClick=&quot;clean3D()&quot;&gt;
&lt;/p&gt;
&lt;/form&gt;
&lt;script LANGUAGE=&quot;JavaScript1.1&quot; SRC=&quot;../../../<a HREF="../marvin.js.txt">marvin.js</a>&quot;&gt;&lt;/script&gt;
&lt;script LANGUAGE=&quot;JavaScript1.1&quot;&gt;
&lt;!--
</pre><pre class="sh_javascript">
function undo() {
    if(document.MSketch != null) {
        document.MSketch.<a href="../../../help/developer/applets/api/JMSketch.html#undo()">undo()</a>;
    }
}

function redo() {
    if(document.MSketch != null) {
        document.MSketch.<a href="../../../help/developer/applets/api/JMSketch.html#redo()">redo()</a>;
    }
}

function clean2D() {
    if(document.MSketch != null) {
        document.MSketch.<a href="../../../help/developer/applets/api/JMSketch.html#clean2D()">clean2D()</a>;
    }
}

function clean3D() {
    if(document.MSketch != null) {
        document.MSketch.<a href="../../../help/developer/applets/api/JMSketch.html#clean3D()">clean3D()</a>;
    }
}
function importMol(opts) {
	if(document.MSketch != null) {
		var s = document.MolForm.MolTxt.value;
		document.MSketch.<a HREF="../../../help/developer/applets/api/JMSketch.html#setMol(java.lang.String, java.lang.String)">setMol</a>(s, opts);
	} else {
		alert(&quot;Cannot import molecule:\n&quot;+
		      &quot;no JavaScript to Java communication in your browser.\n&quot;);
	}
}
function exportMol(format) {
	if(document.MSketch != null) {
		var s = document.MSketch.<a HREF="../../../help/developer/applets/api/JMSketch.html#getMol(java.lang.String)">getMol</a>(format);
		s = <a HREF="../marvin.js.txt">unix2local</a>(s); // Convert &quot;\n&quot; to local line separator
		document.MolForm.MolTxt.value = s;
	} else {
		alert("Cannot import molecule:\n"+
		      "no JavaScript to Java communication in your browser.\n");
	}
}
msketch_name = &quot;MSketch&quot;;
msketch_begin(&quot;../../..&quot;, 540, 480);
msketch_end();
</pre><pre class="sh_html">
//--&gt;
&lt;/script&gt;
</pre>
</blockquote>


<center><div class="lenia">&nbsp;</div></center>
<p>
It may happen that you want to save space on the web page and visualize
your molecule in a small area. The <a HREF="detach.html">next example</a>
shows how to fit the applet into a small area.</p>

</body>
</html>
